package cn.hpu.mobile_bank.controller;


import cn.hpu.mobile_bank.domain.Account;
import cn.hpu.mobile_bank.dto.resp.AccountSelectResp;
import cn.hpu.mobile_bank.dto.resp.ApiResult;
import cn.hpu.mobile_bank.service.AccountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "账户管理")
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;


    @GetMapping("/list")
    @Operation(summary = "获取关联账户列表")
    public ApiResult<List<Account>> accountList(){
        return accountService.accountList();
    }

    @GetMapping("/listNot")
    @Operation(summary = "未关联账户列表")
    public ApiResult<List<Account>> accountListNot(){
        return accountService.accountListNot();
    }

    @GetMapping("/association/{id}")
    @Operation(summary = "关联账户")
    public ApiResult<String> association(@PathVariable("id") Integer accountId){
        return accountService.association(accountId);
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "根据id获取账户信息")
    public ApiResult<Account> getAccount(@PathVariable("id") Integer id){
        return ApiResult.success(accountService.getById(id));
    }

    @GetMapping("/accountNameList")
    @Operation(summary = "获取关联的所有账户名称")
    public ApiResult<List<AccountSelectResp>> accountNameList(){
        return accountService.accountNameList();
    }

}
